var utils = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        address: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getdata()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },
	shanchu: function (e) {
		var that = this
		var index = e.currentTarget.dataset.index
		var address = that.data.address
		var id = e.currentTarget.dataset.id
		console.log(id)
		utils.GET({
			url: 'Cart/deladdress',
			params: {
				uid: 60765,
				id: id
			},
			success: function (res) {
				console.log(res.data)
				// if (res.data.status == 1) {
					wx.showModal({
						content: '确定删除此地址吗?',
						success(res) {
							if (res.confirm) {
								address.splice(index, 1)
								that.setData({
									address: address
								})
							}
						}
					})
				// }

			},
		})

	},
    getdata: function() {
        var that = this
        utils.GET({
            url: 'Cart/choose',
            params: {
                //  uid: wx.getStorageSync('uid')
                 uid: 60765
            },
            success: function(res) {
                console.log(res.data)
                that.setData({
					address:res.data.d
                })
            },
        })
    },
	xiugai:function(e){
		var id=e.currentTarget.dataset.id
		wx.navigateTo({
			url: 'newaddress?id='+id,
		})
	},
	selecttap:function(e){
		var that=this
		var index = e.currentTarget.dataset.index
		var address=that.data.address
		var pages = getCurrentPages();
		var currPage = pages[pages.length - 1];   //当前页面
		var prevPage = pages[pages.length - 2];  //上个页面
		//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
		prevPage.setData({
			address:address[index].address
		})
		wx.navigateBack({
		})
	}
})